import { randomSkill } from '@/utils/utils';
import { useEffect } from 'react';
import { Dialog, Toast } from 'react-vant';
import { atkComputed } from '@/utils/attrComputed/index';
import { SkillItem, sprite } from '@/utils/myinterface';
import { history } from 'umi';
import * as _ from 'lodash';
import { SkillItemClass } from '@/utils/skill';
export default (props) => {
  useEffect(() => {
    if (props.curRound !== 'user') {
      // console.log('敌方回合');
      setTimeout(() => {
        atk();
      }, 4000);
    }
  }, [props.curRound]);
  const atk = () => {
    let skillItem = randomSkill(props.boss);
    // console.log('props.boss', props.boss);
    Toast({ message: '敌方使用了' + skillItem.name });

    let skill = new SkillItemClass(props.boss, props.curSprite, skillItem);
    skill.play();
    props.setBoss(skill.mySprite);
    props.setCurSprite(skill.enemySprite);
    if (skill.enemySprite.attr.currAttr.hp > 0) {
      props.changeCurRound('?');
    } else {
      props.changeCurRound('end');
      setTimeout(() => {
        Dialog.alert({
          message: '战斗失败',
        }).then(() => {
          history.push('/');
        });
      }, 0);
    }
  };

  return <>123123</>;
};
